--------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  /Users/TJRyan/Dropbox/Summer work/Kinder/Replication files/xs_coding.log
  log type:  text
 opened on:  11 Aug 2015, 11:34:59

. do "/Users/TJRyan/Dropbox/Summer work/Kinder/Replication files/xs_coding.do"

. * This file creates the XC working dataset used Kinder and Ryan, "Prejudice and Politics R
> e-examined"
. * Analysis was conducted on State/SE 13.1 for Mac (64-bit Intel) 
. 
. * Load raw data
. use "anes2008xs.dta", clear

. 
. *Weights
. gen preweight = V080101

. gen postweight = V080102

. 
. * Race
. gen white = 0

. replace white = 1 if (V081103a==21 | V081103a==25)
(1167 real changes made)

. gen black = 0

. replace black = 1 if (V081103a==22 | V081103a==26)
(570 real changes made)

. gen hispanic = 0

. replace hispanic = 1 if (V081103a<21)
(505 real changes made)

. gen otherrace = 0

. replace otherrace = 1 if white==0 & black==0 & hispanic==0
(80 real changes made)

. 
. * Education
. gen educ = .
(2322 missing values generated)

. replace educ = 0 if V083218x==1 | V083218x==2
(339 real changes made)

. replace educ = 1 if V083218x==3 
(764 real changes made)

. replace educ = 2 if V083218x==4 | V083218x==5
(712 real changes made)

. replace educ = 3 if V083218x==6
(341 real changes made)

. replace educ = 4 if V083218x==7
(152 real changes made)

. 
. lab def educ 0 "No Diploma" 1 "Diploma only" 2 "Some college" 3 "BA" 4 "Adv. Degre"

. lab val educ educ

. 
. * Age
. gen age2 = V081104
(22 missing values generated)

. gen age = (age2-17)/73
(22 missing values generated)

. gen agebin = .
(2322 missing values generated)

. replace agebin = 0 if age2<30
(426 real changes made)

. replace agebin = 1 if age2>=30 & age2<=39
(431 real changes made)

. replace agebin = 2 if age2>=40 & age2<=49
(440 real changes made)

. replace agebin = 3 if age2>=50 & age2<=59
(445 real changes made)

. replace agebin = 4 if age2>=60
(580 real changes made)

. 
. * Gender
. gen female = 0

. replace female = 1 if V081101==2
(1323 real changes made)

. 
. * Region
. gen region = .
(2322 missing values generated)

. replace region = 0 if V081204==1
(254 real changes made)

. replace region = 1 if V081204==2
(397 real changes made)

. replace region = 2 if V081204==3
(1099 real changes made)

. replace region = 3 if V081204==4
(572 real changes made)

. 
. * Party ID
. gen pidr = .
(2322 missing values generated)

. recode pidr (. = 0) if V083098x==0
(pidr: 580 changes made)

. recode pidr (. = .25) if V083098x==1
(pidr: 393 changes made)

. recode pidr (. = .25) if V083098x==2
(pidr: 392 changes made)

. recode pidr (. = .5) if V083098x==3
(pidr: 264 changes made)

. recode pidr (. = .75) if V083098x==4
(pidr: 223 changes made)

. recode pidr (. = .75) if V083098x==5
(pidr: 200 changes made)

. recode pidr (. = 1) if V083098x==6
(pidr: 230 changes made)

. 
. * PID Strength
. gen dempidstr = .
(2322 missing values generated)

. recode dempidstr (. = 0) if V083098x==3
(dempidstr: 264 changes made)

. recode dempidstr (. = .5) if V083098x==2 | V083098x==1
(dempidstr: 785 changes made)

. recode dempidstr (. = 1) if V083098x==0
(dempidstr: 580 changes made)

. 
. gen reppidstr = .
(2322 missing values generated)

. recode reppidstr (. = 0) if V083098x==3
(reppidstr: 264 changes made)

. recode reppidstr (. = .5) if V083098x==4 | V083098x==5
(reppidstr: 423 changes made)

. recode reppidstr (. = 1) if V083098x==6
(reppidstr: 230 changes made)

. 
. gen pidstr = max(dempidstr, reppidstr)
(40 missing values generated)

. 
. * Racial resentment
. alpha V085143 V085144 V085145 V085146, gen(rresent) c

Test scale = mean(unstandardized items)
Reversed items:  V085143 V085146

Average interitem covariance:     .6120699
Number of items in the scale:            4
Scale reliability coefficient:      0.6995

. alpha V085143 V085144 V085145 V085146 if white==1 // .77

Test scale = mean(unstandardized items)
Reversed items:  V085143 V085146

Average interitem covariance:     .6656663
Number of items in the scale:            4
Scale reliability coefficient:      0.7698

. replace rresent = (((rresent + 2)/4)*2)-1
(1811 real changes made)

. 
. * Stereotyping
. gen blazydif = (6 - V083207a + V083207b)/12
(86 missing values generated)

. gen buninteldif = (6 - V083208a + V083208b)/12
(78 missing values generated)

. alpha blazydif buninteldif, gen(stereotype) c

Test scale = mean(unstandardized items)

Average interitem covariance:     .0099897
Number of items in the scale:            2
Scale reliability coefficient:      0.6721

. 
. gen stereo2 = (stereotype*2)-1
(100 missing values generated)

. 
. * General election vote
. gen obvote = .
(2322 missing values generated)

. replace obvote = 1 if V085044a==1
(1025 real changes made)

. replace obvote = 0 if V085044a==3
(514 real changes made)

. gen mcvote = 1-obvote
(783 missing values generated)

. 
. * Primary vote
. gen primvote = .
(2322 missing values generated)

. replace primvote = 1 if V083077a!=.
(891 real changes made)

. replace primvote = 0 if V083077a==12
(353 real changes made)

. 
. * Gov. Assistance
. gen govassist = (V083137-1)/6
(399 missing values generated)

. 
. * Hire blacks
. gen hireblacks2 = .
(2322 missing values generated)

. replace hireblacks2 = 3 if V085157b==1
(1042 real changes made)

. replace hireblacks2 = 2 if V085157b==5
(398 real changes made)

. replace hireblacks2 = 1 if V085157a==5
(148 real changes made)

. replace hireblacks2 = 0 if V085157a==1
(324 real changes made)

. replace hireblacks2 = 2 if V085157==5 & hireblacks2==.
(2 real changes made)

. replace hireblacks2 = 1 if V085157==1 & hireblacks2==.
(2 real changes made)

. gen hireblacks = hireblacks2 / 3
(406 missing values generated)

. 
. * Affect misattribution procedure
. egen blackresps = rownonmiss(V085311 V085312 V085313 V085314 V085315 V085316 V085317 V0853
> 18 V085319 V085320 V085321 V085322 V085323 V085324 V085325 V085326 V085327 V085328  V08532
> 9 V085330 V085331 V085332 V085333 V085334)

. egen bpleas = anycount(V085311 V085312 V085313 V085314 V085315 V085316 V085317 V085318 V08
> 5319 V085320 V085321 V085322 V085323 V085324 V085325 V085326 V085327 V085328  V085329 V085
> 330 V085331 V085332 V085333 V085334), values(1)

. replace bpleas = . if V085334==. // Didn't complete procedure
(403 real changes made, 403 to missing)

. 
. egen bunpleas = anycount(V085311 V085312 V085313 V085314 V085315 V085316 V085317 V085318 V
> 085319 V085320 V085321 V085322 V085323 V085324 V085325 V085326 V085327 V085328  V085329 V0
> 85330 V085331 V085332 V085333 V085334), values(0)

. replace bunpleas = . if V085334==.
(403 real changes made, 403 to missing)

. 
. egen whiteresps = rownonmiss(V085335 V085336 V085337 V085338 V085339 V085340 V085341 V0853
> 42 V085343 V085344 V085345 V085346 V085347 V085348 V085349 V085350 V085351 V085352 V085353
>  V085354 V085355 V085356 V085357 V085358) 

. egen wpleas = anycount(V085335 V085336 V085337 V085338 V085339 V085340 V085341 V085342 V08
> 5343 V085344 V085345 V085346 V085347 V085348 V085349 V085350 V085351 V085352 V085353 V0853
> 54 V085355 V085356 V085357 V085358), values(1) 

. replace wpleas = . if V085358==.
(407 real changes made, 407 to missing)

. 
. egen wunpleas = anycount(V085335 V085336 V085337 V085338 V085339 V085340 V085341 V085342 V
> 085343 V085344 V085345 V085346 V085347 V085348 V085349 V085350 V085351 V085352 V085353 V08
> 5354 V085355 V085356 V085357 V085358), values(0) 

. replace wunpleas = . if V085358==.
(407 real changes made, 407 to missing)

. 
. gen propwpleas = wpleas / whiteresps
(407 missing values generated)

. gen propbpleas = bpleas / blackresps
(403 missing values generated)

. gen wbdif = propwpleas - propbpleas
(407 missing values generated)

. 
. * Identify respondents with all positive or all negative AMP responses
. gen allpos = 0

. replace allpos = 1 if propwpleas==1 & propbpleas==1
(130 real changes made)

. gen allneg = 0

. replace allneg = 1 if propwpleas==0 & propbpleas==0
(57 real changes made)

. 
. * Trim extreme responses from AMP
. gen wbdif2 = wbdif
(407 missing values generated)

. replace wbdif2 = -.5 if wbdif2<-.5
(24 real changes made)

. 
. * Reliability. The remainder of the file is all to calculate reliability of the AMP.
. * The procedure is to create randomly assigned pairs of black and white AMP 
. * items--the random assignment was done externally--and code the pairs as being prejudiced
> ,
. * reverse-prejudiced, or inconsistent. Then, you calculate an alpha coefficient across 
. * these pairs. (Line 24 of the analysis file.)
. 
. rename V085311 bamp1

. rename V085312 bamp2

. rename V085313 bamp3

. rename V085314 bamp4

. rename V085315 bamp5

. rename V085316 bamp6

. rename V085317 bamp7

. rename V085318 bamp8

. rename V085319 bamp9

. rename V085320 bamp10

. rename V085321 bamp11

. rename V085322 bamp12

. rename V085323 bamp13

. rename V085324 bamp14

. rename V085325 bamp15

. rename V085326 bamp16

. rename V085327 bamp17

. rename V085328 bamp18

. rename V085329 bamp19

. rename V085330 bamp20

. rename V085331 bamp21

. rename V085332 bamp22

. rename V085333 bamp23

. rename V085334 bamp24

. 
. rename V085335 wamp1

. rename V085336 wamp2

. rename V085337 wamp3

. rename V085338 wamp4

. rename V085339 wamp5

. rename V085340 wamp6

. rename V085341 wamp7

. rename V085342 wamp8

. rename V085343 wamp9

. rename V085344 wamp10

. rename V085345 wamp11

. rename V085346 wamp12

. rename V085347 wamp13

. rename V085348 wamp14

. rename V085349 wamp15

. rename V085350 wamp16

. rename V085351 wamp17

. rename V085352 wamp18

. rename V085353 wamp19

. rename V085354 wamp20

. rename V085355 wamp21

. rename V085356 wamp22

. rename V085357 wamp23

. rename V085358 wamp24

. 
. * Create pairs of AMP items
. gen ampitem2 = .
(2322 missing values generated)

. replace ampitem2 = 1 if (bamp2==0 & wamp21==1)
(584 real changes made)

. replace ampitem2 = 0 if (bamp2==0 & wamp21==0)
(360 real changes made)

. replace ampitem2 = 0 if (bamp2==1 & wamp21==1)
(664 real changes made)

. replace ampitem2 = -1 if (bamp2==1 & wamp21==0)
(318 real changes made)

. 
. gen ampitem3 = .
(2322 missing values generated)

. replace ampitem3 = 1 if (bamp3==0 & wamp5==1)
(534 real changes made)

. replace ampitem3 = 0 if (bamp3==0 & wamp5==0)
(412 real changes made)

. replace ampitem3 = 0 if (bamp3==1 & wamp5==1)
(745 real changes made)

. replace ampitem3 = -1 if (bamp3==1 & wamp5==0)
(288 real changes made)

. 
. gen ampitem4 = .
(2322 missing values generated)

. replace ampitem4 = 1 if (bamp4==0 & wamp24==1)
(573 real changes made)

. replace ampitem4 = 0 if (bamp4==0 & wamp24==0)
(353 real changes made)

. replace ampitem4 = 0 if (bamp4==1 & wamp24==1)
(710 real changes made)

. replace ampitem4 = -1 if (bamp4==1 & wamp24==0)
(279 real changes made)

. 
. gen ampitem5 = .
(2322 missing values generated)

. replace ampitem5 = 1 if (bamp5==0 & wamp2==1)
(460 real changes made)

. replace ampitem5 = 0 if (bamp5==0 & wamp2==0)
(471 real changes made)

. replace ampitem5 = 0 if (bamp5==1 & wamp2==1)
(708 real changes made)

. replace ampitem5 = -1 if (bamp5==1 & wamp2==0)
(337 real changes made)

. 
. gen ampitem6 = .
(2322 missing values generated)

. replace ampitem6 = 1 if (bamp6==0 & wamp3==1)
(515 real changes made)

. replace ampitem6 = 0 if (bamp6==0 & wamp3==0)
(414 real changes made)

. replace ampitem6 = 0 if (bamp6==1 & wamp3==1)
(742 real changes made)

. replace ampitem6 = -1 if (bamp6==1 & wamp3==0)
(305 real changes made)

. 
. gen ampitem7 = .
(2322 missing values generated)

. replace ampitem7 = 1 if (bamp7==0 & wamp11==1)
(526 real changes made)

. replace ampitem7 = 0 if (bamp7==0 & wamp11==0)
(409 real changes made)

. replace ampitem7 = 0 if (bamp7==1 & wamp11==1)
(751 real changes made)

. replace ampitem7 = -1 if (bamp7==1 & wamp11==0)
(279 real changes made)

. 
. gen ampitem8 = .
(2322 missing values generated)

. replace ampitem8 = 1 if (bamp8==0 & wamp12==1)
(523 real changes made)

. replace ampitem8 = 0 if (bamp8==0 & wamp12==0)
(400 real changes made)

. replace ampitem8 = 0 if (bamp8==1 & wamp12==1)
(723 real changes made)

. replace ampitem8 = -1 if (bamp8==1 & wamp12==0)
(312 real changes made)

. 
. gen ampitem9 = .
(2322 missing values generated)

. replace ampitem9 = 1 if (bamp9==0 & wamp14==1)
(523 real changes made)

. replace ampitem9 = 0 if (bamp9==0 & wamp14==0)
(394 real changes made)

. replace ampitem9 = 0 if (bamp9==1 & wamp14==1)
(754 real changes made)

. replace ampitem9 = -1 if (bamp9==1 & wamp14==0)
(283 real changes made)

. 
. gen ampitem10 = .
(2322 missing values generated)

. replace ampitem10 = 1 if (bamp10==0 & wamp20==1)
(541 real changes made)

. replace ampitem10 = 0 if (bamp10==0 & wamp20==0)
(374 real changes made)

. replace ampitem10 = 0 if (bamp10==1 & wamp20==1)
(716 real changes made)

. replace ampitem10 = -1 if (bamp10==1 & wamp20==0)
(302 real changes made)

. 
. gen ampitem11 = .
(2322 missing values generated)

. replace ampitem11 = 1 if (bamp11==0 & wamp17==1)
(520 real changes made)

. replace ampitem11 = 0 if (bamp11==0 & wamp17==0)
(388 real changes made)

. replace ampitem11 = 0 if (bamp11==1 & wamp17==1)
(733 real changes made)

. replace ampitem11 = -1 if (bamp11==1 & wamp17==0)
(296 real changes made)

. 
. gen ampitem12 = .
(2322 missing values generated)

. replace ampitem12 = 1 if (bamp12==0 & wamp19==1)
(531 real changes made)

. replace ampitem12 = 0 if (bamp12==0 & wamp19==0)
(387 real changes made)

. replace ampitem12 = 0 if (bamp12==1 & wamp19==1)
(726 real changes made)

. replace ampitem12 = -1 if (bamp12==1 & wamp19==0)
(290 real changes made)

. 
. gen ampitem13 = .
(2322 missing values generated)

. replace ampitem13 = 1 if (bamp13==0 & wamp23==1)
(520 real changes made)

. replace ampitem13 = 0 if (bamp13==0 & wamp23==0)
(377 real changes made)

. replace ampitem13 = 0 if (bamp13==1 & wamp23==1)
(703 real changes made)

. replace ampitem13 = -1 if (bamp13==1 & wamp23==0)
(320 real changes made)

. 
. gen ampitem14 = .
(2322 missing values generated)

. replace ampitem14 = 1 if (bamp14==0 & wamp8==1)
(505 real changes made)

. replace ampitem14 = 0 if (bamp14==0 & wamp8==0)
(422 real changes made)

. replace ampitem14 = 0 if (bamp14==1 & wamp8==1)
(717 real changes made)

. replace ampitem14 = -1 if (bamp14==1 & wamp8==0)
(303 real changes made)

. 
. gen ampitem15 = .
(2322 missing values generated)

. replace ampitem15 = 1 if (bamp15==0 & wamp4==1)
(546 real changes made)

. replace ampitem15 = 0 if (bamp15==0 & wamp4==0)
(400 real changes made)

. replace ampitem15 = 0 if (bamp15==1 & wamp4==1)
(712 real changes made)

. replace ampitem15 = -1 if (bamp15==1 & wamp4==0)
(286 real changes made)

. 
. gen ampitem16 = .
(2322 missing values generated)

. replace ampitem16 = 1 if (bamp16==0 & wamp16==1)
(523 real changes made)

. replace ampitem16 = 0 if (bamp16==0 & wamp16==0)
(405 real changes made)

. replace ampitem16 = 0 if (bamp16==1 & wamp16==1)
(724 real changes made)

. replace ampitem16 = -1 if (bamp16==1 & wamp16==0)
(285 real changes made)

. 
. gen ampitem17 = .
(2322 missing values generated)

. replace ampitem17 = 1 if (bamp17==0 & wamp22==1)
(515 real changes made)

. replace ampitem17 = 0 if (bamp17==0 & wamp22==0)
(385 real changes made)

. replace ampitem17 = 0 if (bamp17==1 & wamp22==1)
(749 real changes made)

. replace ampitem17 = -1 if (bamp17==1 & wamp22==0)
(274 real changes made)

. 
. gen ampitem18 = .
(2322 missing values generated)

. replace ampitem18 = 1 if (bamp18==0 & wamp15==1)
(496 real changes made)

. replace ampitem18 = 0 if (bamp18==0 & wamp15==0)
(429 real changes made)

. replace ampitem18 = 0 if (bamp18==1 & wamp15==1)
(716 real changes made)

. replace ampitem18 = -1 if (bamp18==1 & wamp15==0)
(291 real changes made)

. 
. gen ampitem19 = .
(2322 missing values generated)

. replace ampitem19 = 1 if (bamp19==0 & wamp7==1)
(564 real changes made)

. replace ampitem19 = 0 if (bamp19==0 & wamp7==0)
(387 real changes made)

. replace ampitem19 = 0 if (bamp19==1 & wamp7==1)
(680 real changes made)

. replace ampitem19 = -1 if (bamp19==1 & wamp7==0)
(300 real changes made)

. 
. gen ampitem20 = .
(2322 missing values generated)

. replace ampitem20 = 1 if (bamp20==0 & wamp10==1)
(524 real changes made)

. replace ampitem20 = 0 if (bamp20==0 & wamp10==0)
(383 real changes made)

. replace ampitem20 = 0 if (bamp20==1 & wamp10==1)
(725 real changes made)

. replace ampitem20 = -1 if (bamp20==1 & wamp10==0)
(299 real changes made)

. 
. gen ampitem21 = .
(2322 missing values generated)

. replace ampitem21 = 1 if (bamp21==0 & wamp13==1)
(491 real changes made)

. replace ampitem21 = 0 if (bamp21==0 & wamp13==0)
(401 real changes made)

. replace ampitem21 = 0 if (bamp21==1 & wamp13==1)
(764 real changes made)

. replace ampitem21 = -1 if (bamp21==1 & wamp13==0)
(271 real changes made)

. 
. gen ampitem22 = .
(2322 missing values generated)

. replace ampitem22 = 1 if (bamp22==0 & wamp9==1)
(551 real changes made)

. replace ampitem22 = 0 if (bamp22==0 & wamp9==0)
(360 real changes made)

. replace ampitem22 = 0 if (bamp22==1 & wamp9==1)
(731 real changes made)

. replace ampitem22 = -1 if (bamp22==1 & wamp9==0)
(282 real changes made)

. 
. gen ampitem23 = .
(2322 missing values generated)

. replace ampitem23 = 1 if (bamp23==0 & wamp18==1)
(548 real changes made)

. replace ampitem23 = 0 if (bamp23==0 & wamp18==0)
(396 real changes made)

. replace ampitem23 = 0 if (bamp23==1 & wamp18==1)
(723 real changes made)

. replace ampitem23 = -1 if (bamp23==1 & wamp18==0)
(255 real changes made)

. 
. gen ampitem24 = .
(2322 missing values generated)

. replace ampitem24 = 1 if (bamp24==0 & wamp6==1)
(542 real changes made)

. replace ampitem24 = 0 if (bamp24==0 & wamp6==0)
(396 real changes made)

. replace ampitem24 = 0 if (bamp24==1 & wamp6==1)
(712 real changes made)

. replace ampitem24 = -1 if (bamp24==1 & wamp6==0)
(269 real changes made)

. 
. save "xs_working.dta", replace
file xs_working.dta saved

. 
end of do-file

. log close
      name:  <unnamed>
       log:  /Users/TJRyan/Dropbox/Summer work/Kinder/Replication files/xs_coding.log
  log type:  text
 closed on:  11 Aug 2015, 11:35:05
--------------------------------------------------------------------------------------------
